//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <protocol.h>
#include <reply.h>
#include "cservice.h"

EXTERN CServiceCentral *s_pServiceCentral;

DECL_HANDLER(register)
{
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->Register(req->processId,
                                     &req->clsid,
                                     &req->iid,
                                     req->uIndex,
                                     &reply->oid);
}

DECL_HANDLER(unregister)
{
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->Unregister(req->processId, req->oid);
}

DECL_HANDLER(register_common)
{
    WString name = (wchar_t*)get_req_data(req, 0);

    assert (!name.IsNullOrEmpty());
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->RegisterCommon(name, req->processId,
                                          &req->clsid, &req->iid,
                                          req->uIndex, &reply->oid);
}

DECL_HANDLER(unregister_common)
{
    WString name = (wchar_t*)get_req_data(req, 0);

    assert (!name.IsNullOrEmpty());
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->UnregisterCommon(name, req->processId);
}

DECL_HANDLER(resolve_common)
{
    WString name = (wchar_t*)get_req_data(req, 0);

    assert (!name.IsNullOrEmpty());
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->ResolveCommon(name, &reply->processId,
                                        &reply->type, &reply->oid,
                                        &reply->clsid, &reply->uIndex);
}

DECL_HANDLER(get_process_id)
{
    assert (NULL != s_pServiceCentral);
    return s_pServiceCentral->GetProcessIdByServiceOid(req->oid, &reply->processId);
}

DECL_HANDLER(register_service)
{
    WString name = (wchar_t*)get_req_data(req, 0);

    assert (!name.IsNullOrEmpty());
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->RegisterService(name, req->processId, req->oid);
}

DECL_HANDLER(wait_service)
{
    WString name = (wchar_t*)get_req_data(req, 0);

    assert (!name.IsNullOrEmpty());
    assert (NULL != s_pServiceCentral);

    return s_pServiceCentral->WaitService(name, req->msTimeout, &reply->result);
}

DECL_HANDLER(attach_service)
{
    assert (NULL != s_pServiceCentral);
    return s_pServiceCentral->AttachImportService(req->processId, req->oid);
}

DECL_HANDLER(detach_service)
{
    assert (NULL != s_pServiceCentral);
    return s_pServiceCentral->DetachImportService(req->processId, req->oid);
}

